package top.pcat.config;

import lombok.Data;
import top.pcat.Server;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Data
public class KafkaConfig {

    private String bootstrapServers;

    private String producerRetries;
    private String producerBatchSize;
    private String producerBufferMemory;
    private String producerKeySerializer;
    private String producerValueSerializer;
    private String producerAcks;

    private String consumerGroupId;
    private String consumerEnableAutoCommit;
    private String consumerAutoOffsetReset;
    private String consumerKeyDeserializer;
    private String consumerValueDeserializer;

    private String topic = "test";


    public KafkaConfig() {
        try {
            InputStream inputStream = Server.class.getClassLoader().getResourceAsStream("server.properties");
            Properties properties = new Properties();
            properties.load(inputStream);

            this.bootstrapServers = properties.getProperty("kafka.bootstrapServers");

            this.producerBatchSize = properties.getProperty("kafka.producer.batchSize");
            this.producerBufferMemory = properties.getProperty("kafka.producer.bufferMemory");
            this.producerKeySerializer = properties.getProperty("kafka.producer.keySerializer");
            this.producerValueSerializer = properties.getProperty("kafka.producer.valueSerializer");
            this.producerAcks = properties.getProperty("kafka.producer.acks");

            this.consumerGroupId = properties.getProperty("kafka.consumer.groupId");
            this.consumerEnableAutoCommit = properties.getProperty("kafka.consumer.enableAutoCommit");
            this.consumerAutoOffsetReset = properties.getProperty("kafka.consumer.autoOffsetReset");
            this.consumerKeyDeserializer = properties.getProperty("kafka.consumer.keyDeserializer");
            this.consumerValueDeserializer = properties.getProperty("kafka.consumer.valueDeserializer");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
